package com.wanjia.estate.service.bdservice.FjtService;

import com.spire.xls.ExcelPicture;
import com.spire.xls.ExcelVersion;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import com.wanjia.estate.pojo.entity.Fjtwyjdetzfqrs;
import com.wanjia.estate.pojo.entity.Sjd;
import com.wanjia.estate.utils.BarcodeGeneratorUtil;
import com.wanjia.estate.utils.Base64Util;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;

@Slf4j
@Service
public class ExcelAddImgFjtService {
    public String ExcelAddImg(String excelPath, Fjtwyjdetzfqrs fjtwyjdetzfqrs) throws IOException {

        File file = new File(excelPath);
        String absolutePath = file.getAbsolutePath();
        String name = absolutePath.split("\\.")[0];
        Base64Util.stringToImage(fjtwyjdetzfqrs.getNsrsqrqz(), name+"qm1");//生成签名

        //创建Workbook实例
        Workbook workbook = new Workbook();
        //加载Excel文档
        workbook.loadFromFile(excelPath);
        //获取第一张工作表
        Worksheet sheet = workbook.getWorksheets().get(0);

        //添加图片到工作表的指定位置
        ExcelPicture pic2 = sheet.getPictures().add(15, 6,name+"qm1.png");


        //设置图片的宽度和高度
        pic2.setWidth(100);
        pic2.setHeight(40);
        //保存文档
        workbook.saveToFile(excelPath, ExcelVersion.Version2013);

        return absolutePath;
    }
}
